package org.xjh.selectimagevideo;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.ArrayList;

public class BottomSheetActivity extends AppCompatActivity {
    private static final String TAG = "Behavior";
    BottomSheetBehavior sheetBehavior;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_bottom_sheet);
        View bottomSheet = findViewById(R.id.bottom_sheet);
        sheetBehavior = BottomSheetBehavior.from(bottomSheet);
        sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                switch (newState) {
                    case BottomSheetBehavior.STATE_DRAGGING:
                        Log.e(TAG, "onStateChanged: STATE_DRAGGING");
                        break;
                    case BottomSheetBehavior.STATE_COLLAPSED:
                        Log.e(TAG, "onStateChanged: STATE_COLLAPSED");
                        break;
                    case BottomSheetBehavior.STATE_EXPANDED:
                        Log.e(TAG, "onStateChanged: STATE_EXPANDED");
                        break;
                    case BottomSheetBehavior.STATE_HIDDEN:
                        Log.e(TAG, "onStateChanged: STATE_HIDDEN");
                        break;
                    case BottomSheetBehavior.STATE_SETTLING:
                        Log.e(TAG, "onStateChanged: STATE_SETTLING");
                        break;


                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {

            }
        });



    }

    public void onShow(View view) {
//        if(sheetBehavior.getState() ==BottomSheetBehavior.STATE_EXPANDED){
//            sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
//        }
//        else{
//            sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
//        }

//       new SelectFolderFragment().show(getSupportFragmentManager(),"dialog");

        Intent intent = new Intent(this,SelectImageVideoAct.class);
        intent.putExtra(SelectImageVideoAct.KEY_SELECT_NUM,1);
        intent.putExtra(SelectImageVideoAct.KEY_CAMERA_SHOW,false);
        intent.putExtra(SelectImageVideoAct.KEY_TYPE,SelectImageVideoView.TYPE_AVATAR);
        startActivityForResult(intent,2);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == 2&& resultCode==RESULT_OK){

            ArrayList<String> path = data.getStringArrayListExtra(SelectImageVideoAct.KEY_RESULT);

            Log.e(TAG, "onActivityResult: "+path.toString());
        }
    }
}
